package com.doadway.dwcms.assistant.biz.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.doadway.dwcms.assistant.biz.AcquisitionBiz;
import com.doadway.dwcms.assistant.dao.AcquisitionMapper;
import com.doadway.dwcms.assistant.pojo.Acquisition;
import com.doadway.dwcms.assistant.pojo.AcquisitionExample;
import com.doadway.dwcms.assistant.pojo.AcquisitionExample.Criteria;
@Service
public class AcquisitionBizImpl implements AcquisitionBiz {
	@Resource
	AcquisitionMapper acquisitionDAO;
	@Override
	public boolean saveOrUpdateAcquisition(Acquisition acquisition) {
		if(acquisition==null){return false;}
		if(findAcquisitionById(acquisition.getAcquisitionId())!=null){
			return acquisitionDAO.updateByPrimaryKey(acquisition)>0;
		}else{
			return acquisitionDAO.insert(acquisition)>0;
		}
	}

	@Override
	public boolean batchDeleteAcquisition(String[] advertisingIds) {
		Integer flag=0;
		for(String id:advertisingIds){
			acquisitionDAO.deleteByPrimaryKey(Integer.parseInt(id));
			flag++;
		}
		if(flag==advertisingIds.length){
			return true;
		}
		return false;
	}

	@Override
	public Acquisition findAcquisitionById(Integer acquisitionId) {
		return acquisitionDAO.selectByPrimaryKey(acquisitionId);
	}

	@Override
	public List<Acquisition> findAllAcquisition() {
		AcquisitionExample example =new AcquisitionExample();
		example.setOrderByClause("ACQUISITION_ID");
		Criteria acqCri=example.createCriteria();
		acqCri.andAcquisitionIdIsNotNull();
		return acquisitionDAO.selectByExample(example );
	}

	@Override
	public void startAcquisitionById(Integer acquisitionId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pauseAcquisitionById(Integer acquisitionId) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void stopAcquisitionById(Integer acquisitionId) {
		// TODO Auto-generated method stub
		
	}

}
